//
//  WLViewController.m
//  KnowEveryThings
//
//  Created by lanou3g on 16/5/6.
//  Copyright © 2016年 王玲. All rights reserved.
//

#import "WLViewController.h"
#import "WLReadingController.h"
#import "WLNetWorkRequestManager.h"
#import "WLModelCell.h"
@interface WLViewController ()<UIWebViewDelegate>
@end
NSString *nsurl;
@implementation WLViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor greenColor];
    
    
    [WLNetWorkRequestManager requestURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://comment.api.163.com/api/json/post/list/new/hot/news_shehui7_bbs/%@/0/5/10/2/2",self.vid]] Method:WL_GET Params:nil Result:^(NSData *data, NSURLResponse *response, NSError *error) {
        
        if (data) {
            NSMutableDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil];
            NSString  *docUrl = jsonDict[@"docUrl"];
            nsurl = docUrl;
            NSLog(@"%@",docUrl);
        }
        

        
    }];
    
    [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(asdh) userInfo:nil repeats:NO];
   

}

//等比例缩放
- (void)webViewDidFinishLoad:(UIWebView *)webView {
    [webView stringByEvaluatingJavaScriptFromString:
     @"var script = document.createElement('script');"
     "script.type = 'text/javascript';"
     "script.text = \"function ResizeImages() { "
     "var myimg,oldwidth;"
     "var maxwidth=380;"
     //缩放系数
     "for(i=0;i <document.images.length;i++){"
     "myimg = document.images[i];"
     "if(myimg.width > maxwidth){"
     "oldwidth = myimg.width;"
     
     "myimg.width = maxwidth;"
     "myimg.height = myimg.height * (maxwidth/oldwidth);"
     "}"
     "}"
     "}\";"
     "document.getElementsByTagName('head')[0].appendChild(script);"];
    [webView stringByEvaluatingJavaScriptFromString:@"ResizeImages();"];
}
-(void)asdh
{
    UIWebView *webView = [[UIWebView alloc] init];
    webView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.bounds.size.height);
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:nsurl]]];
     webView.delegate = self;
     [self.view addSubview:webView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
